package com.touna.controller;

import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.alibaba.fastjson.JSONObject;
import com.touna.bean.VoiceRecord;
import com.touna.com.touna.service.VoiceService;
import com.touna.tools.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class VoiceController {

    @Autowired
    VoiceService voiceService;


    @ResponseBody @RequestMapping(value = "/loadVoice",produces={"text/html;charset=UTF-8;application/json;"})
    public String loadVoice(HttpServletRequest request, HttpServletResponse response) throws IOException{
        int pageIndex =  Integer.valueOf(request.getParameter("page"));
        int pageSize =  Integer.valueOf(request.getParameter("rows"));
        String keyword =  request.getParameter("keyword");
        String wordType = request.getParameter("word_type");
        Page page = new  Page(pageIndex,pageSize);
        VoiceRecord record = new  VoiceRecord();
        record.setWordType(wordType);
        record.setChineseName(keyword);
        Page pageResult = voiceService.qureyVoices(page,record);
        String resultStr = JSONObject.toJSONString(pageResult);
        return resultStr;
    }


    @RequestMapping("/menuSys")
    public ModelAndView queryItems()throws Exception{
        ModelAndView modelAndView  = new ModelAndView();
        //指定视图
        modelAndView.setViewName("/WEB-INF/jsp/voice.jsp");
        return modelAndView;
    }
}